package jpa_objects;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

/**
 * @author Alejandro Casas
 * @version 1.0
 * @created 10-Dec-2012 1:01:03 AM
 */
@Entity
@NamedQueries({
	@NamedQuery(name="searchPlayers", query="Select p from Player p  inner join fetch p.active_sports as s" +
			"  inner join fetch p.city as c where s.name = :sport  and c.name = :city and c.country = :country" +
			" and p.active = true"),
	@NamedQuery(name="searchPlayersWraper",query="Select p from Player p  inner join fetch p.active_sports as s" +
			"  inner join fetch p.city as c where s.wraper = :wraper  and c.name = :city and c.country = :country" +
			" and p.active = true")
})
@PrimaryKeyJoinColumn(name="realMail")
public class Player extends User {

	private boolean active;
	private String birthday;
	private String endDate;
	//private long id;
	private boolean privacy;
	//Strings de la forma nombreDeport,numeroRatings
	
	private List<Sport_calification> sport_califications;
	private String startDate;
	private List<Instructor> instructors;
	private List<Player> friend_applicants;
	private List<Player> friends;
	private City active_city;
	private double active_lat;
	private double active_lng;
	
	private List<Sport> active_sports;
	private List<Event_suggestion> event_suggestions;
	private String gender;
	
	
	

	
	/**
	 * @return the active_city
	 */
	@OneToOne(targetEntity=City.class,cascade=CascadeType.ALL)
	public City getActive_city() {
		return active_city;
	}

	/**
	 * @param active_city the active_city to set
	 */
	public void setActive_city(City active_city) {
		this.active_city = active_city;
	}

	/**
	 * @return the active_lat
	 */
	public double getActive_lat() {
		return active_lat;
	}

	/**
	 * @param active_lat the active_lat to set
	 */
	public void setActive_lat(double active_lat) {
		this.active_lat = active_lat;
	}

	/**
	 * @return the active_lng
	 */
	public double getActive_lng() {
		return active_lng;
	}

	/**
	 * @param active_lng the active_lng to set
	 */
	public void setActive_lng(double active_lng) {
		this.active_lng = active_lng;
	}

	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}

	/**
	 * @param gender the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * @return the sport_califications
	 */
	@OneToMany(targetEntity=Sport_calification.class,cascade=CascadeType.ALL)
	public List<Sport_calification> getSport_califications() {
		return sport_califications;
	}

	/**
	 * @param sport_califications the sport_califications to set
	 */
	public void setSport_califications(List<Sport_calification> sport_califications) {
		this.sport_califications = sport_califications;
	}

	/*
	 * @return the active
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * @param active the active to set
	 */
	public void setActive(boolean active) {
		this.active = active;
	}

	/**
	 * @return the birthday
	 */
	public String getBirthday() {
		return birthday;
	}

	/**
	 * @param birthday the birthday to set
	 */
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the id
	 *
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 *
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the privacy
	 */
	public boolean isPrivacy() {
		return privacy;
	}

	/**
	 * @param privacy the privacy to set
	 */
	public void setPrivacy(boolean privacy) {
		this.privacy = privacy;
	}

	

	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the instructors
	 */
	@OneToMany(targetEntity=Instructor.class,cascade=CascadeType.ALL)
	public List<Instructor> getInstructors() {
		return instructors;
	}

	/**
	 * @param instructors the instructors to set
	 */
	public void setInstructors(List<Instructor> instructors) {
		this.instructors = instructors;
	}

	/**
	 * @return the friend_applicants
	 */
	@OneToMany(targetEntity=Player.class,cascade=CascadeType.ALL)
	public List<Player> getFriend_applicants() {
		return friend_applicants;
	}

	/**
	 * @param friend_applicants the friend_applicants to set
	 */
	public void setFriend_applicants(List<Player> friend_applicants) {
		this.friend_applicants = friend_applicants;
	}

	/**
	 * @return the friends
	 */
	@OneToMany(targetEntity=Player.class,cascade=CascadeType.ALL)
	public List<Player> getFriends() {
		return friends;
	}

	/**
	 * @param friends the friends to set
	 */
	public void setFriends(List<Player> friends) {
		this.friends = friends;
	}

	
	

	/**
	 * @return the active_sports
	 */
	@OneToMany(targetEntity=Sport.class,cascade=CascadeType.ALL)
	public List<Sport> getActive_sports() {
		return active_sports;
	}

	/**
	 * @param active_sports the active_sports to set
	 */
	public void setActive_sports(List<Sport> active_sports) {
		this.active_sports = active_sports;
	}

	/**
	 * @return the event_suggestions
	 */
	@OneToMany(targetEntity=Event_suggestion.class,cascade=CascadeType.ALL)
	public List<Event_suggestion> getEvent_suggestions() {
		return event_suggestions;
	}

	/**
	 * @param event_suggestions the event_suggestions to set
	 */
	public void setEvent_suggestions(List<Event_suggestion> event_suggestions) {
		this.event_suggestions = event_suggestions;
	}

	public Player(){

	}

	/**
	 * @param carrier
	 * @param country
	 * @param description
	 * @param joinDate
	 * @param mail
	 * @param miniPicture
	 * @param name
	 * @param num_ratings
	 * @param password
	 * @param phone
	 * @param picture
	 * @param rating
	 * @param status
	 * @param active
	 * @param birthday
	 * @param endDate
	 * @param privacy
	 * @param ratings_por_deporte
	 * @param startDate
	 * @param city
	 */
	public Player(String carrier, String country, String description,
			String joinDate, String mail, String miniPicture, String name,
			int num_ratings, String password, String phone, String picture,
			int rating, String status, boolean active, String birthday,
			String endDate, boolean privacy,
			String startDate, City city,String gender) {
		super(carrier, country, description, joinDate, mail, miniPicture, name,
				num_ratings, password, phone, picture, rating, status,city);
		this.active = active;
		this.active_city=null;
		this.active_lat=0;
		this.active_lng=0;
		this.birthday = birthday;
		this.endDate = endDate;
		this.privacy = privacy;
		this.sport_califications=new ArrayList<Sport_calification>();
		this.startDate = startDate;
		this.gender=gender;
		this.instructors=new ArrayList<Instructor>();
		friend_applicants=new ArrayList<Player>();
		friends=new ArrayList<Player>();
		
		active_sports=new ArrayList<Sport>();
		event_suggestions=new ArrayList<Event_suggestion>();
	}

	public void finalize() throws Throwable {
		super.finalize();
	}

}